package com.example.mall.web.controller;

import com.example.mall.domain.PaymentCallbacks;
import com.example.mall.dto.PaymentCallbacksDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.PaymentCallbacksQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IPaymentCallbacksService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/paymentCallbacks")
public class PaymentCallbacksController {

    @Autowired
    public IPaymentCallbacksService paymentCallbacksService;

    /**
     * 分页查询支付回调记录表信息
     * @param paymentCallbacksQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询支付回调记录表信息",notes = "分页查询支付回调记录表信息",httpMethod = "GET")
    public JSONResult queryPage(PaymentCallbacksQuery paymentCallbacksQuery){
        PageDTO<PaymentCallbacksDto> paymentCallbacksDtoPageDTO = paymentCallbacksService.queryPage(paymentCallbacksQuery);
        return JSONResult.success("查询成功",paymentCallbacksDtoPageDTO);
    }

    /**
     * 根据id查询支付回调记录表信息
     * @param callbackId
     * @return
     */
    @GetMapping("query/{callbackId}")
    @ApiOperation(value = "根据id查询支付回调记录表信息",notes = "根据id查询支付回调记录表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("callbackId")Long callbackId){
        //1.根据id查询用户信息
        if (callbackId == null){
            throw new GlobalCustomerException(ErrorEnumCode.CALLBACKID_NOT_ID);
        }
        PaymentCallbacks paymentCallbacks = paymentCallbacksService.getById(callbackId);
        return JSONResult.success("查询成功",paymentCallbacks);
    }

    /**
     * 根据id查询支付回调记录表信息
     * @param callbackId
     * @return
     */
    @GetMapping("queryPaymentCallbacksById/{callbackId}")
    @ApiOperation(value = "根据id查询支付回调记录表信息",notes = "根据id查询支付回调记录表信息",httpMethod = "GET")
    public JSONResult queryPaymentCallbacksById(@PathVariable("callbackId")Long callbackId){
        //1.根据id查询用户信息
        if (callbackId == null){
            throw new GlobalCustomerException(ErrorEnumCode.LOGINID_NOT_ID);
        }
        PaymentCallbacks paymentCallbacks = paymentCallbacksService.queryPaymentCallbacksById(callbackId);
        return JSONResult.success("查询成功",paymentCallbacks);
    }

    /**
     * 查询全部支付回调记录表信息
     * @param
     * @return
     */
    @GetMapping("queryPaymentCallbacksList")
    @ApiOperation(value = "查询全部支付回调记录表信息",notes = "查询全部支付回调记录表信息",httpMethod = "GET")
    public JSONResult queryPaymentCallbacksList(){
        List<PaymentCallbacks> paymentCallbacks = paymentCallbacksService.queryPaymentCallbacksList();
        return JSONResult.success("查询成功",paymentCallbacks);
    }

    /**
     * 新增支付回调记录表
     * @param paymentCallbacksDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增支付回调记录表",notes = "新增支付回调记录表",httpMethod = "POST")
    public JSONResult insert(@RequestBody PaymentCallbacksDto paymentCallbacksDto){
        paymentCallbacksService.insert(paymentCallbacksDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改支付回调记录表信息
     * @param paymentCallbacksDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改支付回调记录表信息",notes = "修改支付回调记录表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody PaymentCallbacksDto paymentCallbacksDto){
        paymentCallbacksService.update(paymentCallbacksDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除支付回调记录表信息
     * @param callbackId
     * @return
     */
    @PostMapping("delete/{callbackId}")
    @ApiOperation(value = "删除支付回调记录表信息",notes = "删除支付回调记录表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("callbackId") Long callbackId) {
        paymentCallbacksService.delete(callbackId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除支付回调记录表信息
     * @param callbackIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除支付回调记录表信息",notes = "批量删除支付回调记录表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> callbackIds) {
        paymentCallbacksService.deleteBatch(callbackIds);
        return JSONResult.success("批量删除成功");
    }
}
